package demo3;

import java.io.FileNotFoundException;
import java.io.IOException;

class Person implements Cloneable{
    public String name;

    public Person(String name) {
        this.name = name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}

public class Test {
    public static void main(String[] args) {
        System.out.println("before.......");

        try {
            System.out.println(10/0);
        } catch (ArithmeticException e) {
            System.out.println("我来处理 ArithmeticException 了");
        } catch (Exception e) {
            System.out.println("我来处理 NullPointerException 了");
        }

        System.out.println("after........");
    }
    public static void main5(String[] args) {
        System.out.println("before.......");

        /*try {
            System.out.println(10/0);
        } catch (ArithmeticException e) {
            System.out.println("我来处理 ArithmeticException 了");
        } catch (NullPointerException e) {
            System.out.println("我来处理 NullPointerException 了");
        }*/

        //以下方式等同上面，但是少用
        try {
            System.out.println("haha");
            System.out.println(10/0);
            System.out.println("gege");
        } catch (ArithmeticException | NullPointerException e) {
            System.out.println("我来处理 ArithmeticException 了");
        }

        System.out.println("after........");
    }

    /*//public void OpenConfig(String filename) throws IOException, FileNotFoundException{
    //FileNotFoundException 继承于 IOException
    public void OpenConfig(String filename) throws IOException{

    }//这两种方式是一样的*/
    public static void func() throws CloneNotSupportedException{
        int a = 10;
        if (a == 10) {
            throw new CloneNotSupportedException("hahaha");
        }
    }

    public static void main4(String[] args) throws CloneNotSupportedException {
        try {
            func();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }


    public static void main3(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person("zhansan");
        Person person2 = (Person) person1.clone();
        System.out.println(person2);
    }

    /*public static void func() {
        func();
    }*/
    public static void main2(String[] args) {
        /*func();*/
    }
    public static void main1(String[] args) {
        /*System.out.println(10/0);
        System.out.println("abcd");*//*

        int[] array = {1,2,3,4};
        System.out.println(array[10]);*/
    }
}
